@extends('shop-backend::layouts.bootstrap_modal')

@section('modal_class')
    modal-lg
@stop
@section('title')
    @if($action == 'view')
        查看已选择门店
    @elseif($action == 'view_exclude')
        查看已排除门店
    @else
        选择门店
    @endif
@stop

@section('after-styles-end')
    {!! Html::style(env("APP_URL").'/assets/backend/libs/ladda/ladda-themeless.min.css') !!}
@stop


@section('body')
    <div class="row">
        <div class="col-md-12 clearfix">
            <div class="row">
                <input type="hidden" name="field" value="name" class="form-control">
                <label class="col-sm-2">门店名称：</label>
                <div class="col-sm-6">
                    <input type="text" name="value" placeholder="Search" value="{{!empty(request('value'))?request('value'):''}}" class=" form-control">
                </div>
                <div class="col-sm-2">
                    <button type="button" id="send" class="ladda-button btn btn-primary">搜索</button>
                </div>
            </div>
        </div>
        <div class="clearfix"></div>
        <div class="hr-line-dashed "></div>
        <div class="panel-body">
            <h3 class="header">请选择门店：</h3>
            <div class="table-responsive" id="goodsList">
                <table class="table table-hover table-striped">
                    <thead>
                    <tr>
                        <th>门店名称</th>
                    </tr>
                    </thead>
                    <tbody class="page-goods-list">
                    </tbody>
                </table>
            </div>
            <div class="pages">
            </div>
        </div>
    </div>
    <script type="text/html" id="page-temp">
        <tr>
            <td>
                {#name#}
            </td>
            <td>
                <button onclick="changeShopSelect(this)" class="btn btn-circle {#class#}" type="button" data-id="{#id#}"><i class="fa fa-{#icon#}"></i>
                </button>
            </td>
        </tr>
    </script>
@stop
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/spin.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/ladda.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/ladda/ladda.jquery.min.js') !!}
{!! Html::script(env("APP_URL").'/assets/backend/libs/loader/jquery.loader.min.js') !!}
@section('footer')
    <input type="hidden" id="temp_selected_shop">
    <button type="button" class="btn btn-link" data-dismiss="modal">取消</button>
    <button type="button" onclick="sendShopIds('{{$action}}');" class="ladda-button btn btn-primary"> 确定
    </button>
    @include('shop-backend::promotion.public.modal.script')
    {!! Html::script(env("APP_URL").'/assets/backend/libs/jquery.el/common.js') !!}
    {!! Html::script(env("APP_URL").'/assets/backend/libs/jquery.el/jquery.http.js') !!}
    {!! Html::script(env("APP_URL").'/assets/backend/libs/jquery.el/page/jquery.pages.js') !!}
    <script>
        var action = '{{$action}}';
        var paraDiscountShop = {_token: $('meta[name="_token"]').attr('content')};

        function getList() {
	        var postUrl = '{{route('admin.shop.promotion.getShopData')}}';
	        var selected_shop = $('#selected_shop').val();

	        $('.pages').pages({
		        page: 1,
		        url: postUrl,
		        get: $.http.post.bind($.http),
		        body: {
			        _token: $('meta[name="_token"]').attr('content'),
			        action: action,
			        ids: paraDiscountShop.ids,
			        field: $("input[name=field]").val(),
			        value: $("input[name=value]").val()
		        },
		        marks: {
			        total: 'data.last_page',
			        index: 'data.current_page',
			        data: 'data'
		        }
	        }, function (data) {
		        var html = '';
		        var ids = data.ids;

		        data.data.forEach(function (item) {
			        if (!~ids.indexOf(String(item.id))) {
				        item.class = 'btn-warning unselect';
				        item.icon = 'times';

			        } else {
				        item.class = 'btn-info select';
				        item.icon = 'check';
			        }

			        html += $.convertTemplate('#page-temp', item, '');
		        });
		        $('.page-goods-list').html(html);
	        });
        }

        $(document).ready(function () {
	        $('#temp_selected_shop').val($('#selected_shop').val());
	        paraDiscountShop.ids = $('#temp_selected_shop').val();

	        getList();
        });

        $('#send').on('click', function () {
	        getList();
        });
    </script>
@stop